package test;

import static org.junit.Assert.*;

import java.util.Vector;

import model.*;

import org.junit.Test;

public class test {

	@Test
	public void testNormal() throws Exception {
		Vector<QuantifiedComponent> v1 = new Vector<QuantifiedComponent>();
		Material m1 = Material.create("m1", 3);
		Material m2 = Material.create("m2", 2);
		Material m3 = Material.create("m3", 1);
		Material m4 = Material.create("m4", 4);
		
		QuantifiedComponent qC1 = QuantifiedComponent.create(4, m1);
		QuantifiedComponent qC2 = QuantifiedComponent.create(5, m2);
		QuantifiedComponent qC3 = QuantifiedComponent.create(6, m3);	

		v1.add(qC1);
		v1.add(qC2);
		v1.add(qC3);
		
		MaterialList mL1 = MaterialList.create(v1);
		
		QuantifiedComponent qC4 = QuantifiedComponent.create(7, m3);
		
		mL1.add(qC4);
		
		assertEquals(3,mL1.getMaterials().size());
		assertEquals(13,mL1.getMaterials().lastElement().getQuantity());
		
		QuantifiedComponent qC5 = QuantifiedComponent.create(7, m4);
		
		mL1.add(qC5);
		
		assertEquals(4,mL1.getMaterials().size());
		
		Product p1 = Product.create("p1", 3);
		p1.addPart(m1, 1);
		p1.addPart(m2, 1);
		p1.addPart(m3, 1);
		
		QuantifiedComponent qC6 = QuantifiedComponent.create(1, p1);
		mL1.add(qC6);
		
		assertEquals(5,mL1.getMaterials().size());		
		
		Product p2 = Product.create("p2", 1);
		p2.addPart(m1, 4);
		p2.addPart(m2, 5);
		p2.addPart(m3, 6);
		p2.addPart(m3, 7);
		p2.addPart(m4, 7);
		p2.addPart(p1, 1);
		
		assertNotEquals(mL1,p2.getMaterialList());
		
		Vector<QuantifiedComponent> v2 = new Vector<QuantifiedComponent>();
		v2.add(qC1);
		v2.add(qC2);
		v2.add(qC3);
		
		MaterialList mL2 = MaterialList.create(v2);
		
		mL2.add(qC4);
		mL2.add(qC5);
		mL2.add(QuantifiedComponent.create(1,m1));
		mL2.add(QuantifiedComponent.create(1,m2));
		mL2.add(QuantifiedComponent.create(1,m3));
		
		Manager manager = Manager.getTheManager();
		manager.getAllPartCalls().clear();
		assertEquals(v2, p2.getMaterialList().getMaterials());
		
		assertEquals(8,Manager.getTheManager().getAllPartCalls().size());

	}

}
